package com.mail.portal.modular.controller;

import com.mail.portal.common.controller.BaseController;
import com.mail.portal.modular.model.Product;
import com.mail.portal.modular.model.ProductCategory;
import com.mail.portal.modular.service.IProductCategoryService;
import com.mail.portal.modular.service.IProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * 创建人： Shi Heng
 * 创建时间：2018-04-21 18:24
 * QQ：374696376
 * Description：搜素控制器
 */
@Controller
@RequestMapping("/jhcb/searcher")
public class SearcherController extends BaseController {

    @Resource
    private IProductCategoryService productCategoryService;

    @Resource
    private IProductService productService;

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public String search(@RequestParam(value = "keywords")String keywords, Model model){
        System.out.println(keywords + "-----------------------------");
        List<ProductCategory> categories = productCategoryService.selectAll();
        List<Product> products = productService.selectProducts(keywords, null, null, null);
        model.addAttribute("categories", categories);
        model.addAttribute("keywords",keywords);
        model.addAttribute("products",products);
        return "/search.html";
    }
}
